package com.itgaoshu.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itgaoshu.bean.Bed;
import com.itgaoshu.bean.Departments;
import com.itgaoshu.bean.Doctor;
import com.itgaoshu.bean.Register;
import com.itgaoshu.service.InHospitalPathService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.sound.midi.SoundbankResource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: xiyue
 * Date: 2021/3/22
 * Time: 17:09
 * To change this template use File | Settings | File Templates.
 * Description:
 */
@Controller
@RequestMapping("/liao")
public class InHospitalPathController {
    @Autowired
    private InHospitalPathService inHospitalPathService;
    @RequestMapping("/admin")
    public String toInHospitalMin(){
        return "liao/admin";
    }

    //查询患者信息
    @RequestMapping("/selRegister")
    @ResponseBody
    public Object selRegister(Integer page, Integer limit,Register register){
        //分页查询
        PageHelper.startPage(page, limit);
        //查询未出院的患者信息
        List<Register> selreg=inHospitalPathService.selRegisters(register);
        System.out.println(selreg);
        //把查到的信息放入分页插件中
        PageInfo pageInfo = new PageInfo(selreg);
        Map<String, Object> tableData = new HashMap<String, Object>();
        //这是layui要求返回的json数据格式
        tableData.put("code", 0);
        tableData.put("msg", "");
        //将全部数据的条数作为count传给前台（一共多少条）
        tableData.put("count", pageInfo.getTotal());
        //将分页后的数据返回（每页要显示的数据）
        tableData.put("data", pageInfo.getList());
        //把数据返回到layui中
        return tableData;
    }



    //页面请求查询科室信息
    @RequestMapping("/selDepartment")
    @ResponseBody
    public Object selDepartment(){

        //查询所有科室
        List<Departments> Departments= inHospitalPathService.selDepartment();
        //把查到的科室返回前台下拉框中
        return Departments;
    }

    //页面请求查询医生信息
    @RequestMapping("/selDoctor")
    @ResponseBody
    public Object selDoctor(Integer departmentId){
        System.out.println(departmentId);
        //根据科室查询旗下所有医生
        List<Doctor> doctors = inHospitalPathService.selDoctor(departmentId);
        //把查到的医生返回前台下拉框中
        return doctors;
    }

    //查询床位
    @RequestMapping("/selBed")
    @ResponseBody
    public Object selBed(Integer departmentId){
        Bed bed= new Bed();
        bed.setDepartmentId(departmentId);
        //查询没有人入住的床位
        bed.setState(0);
        List<Bed> beds = inHospitalPathService.selBed(departmentId);
        return beds;
    }


}
